package com.matt.controller.pad;

import com.matt.commons.dto.sso.StaffDTO;
import com.matt.commons.model.StatusResponse;
import com.matt.foundation.constant.CourseConstant;
import com.matt.foundation.query.ClassesCoursePlanQuery;
import com.matt.foundation.vo.course.WebCoursePlanListVo;
import com.matt.service.CourseAuditService;
import com.matt.service.PrepareCourseService;
import com.matt.service.remoteCall.SsoCallService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

import static com.matt.foundation.constant.RequestConstant.TICKET;


@Api(tags ="审核管理")
@RestController
@RequestMapping("/pad/course_audit")
public class PadCourseAuditController {

    @Autowired
    private CourseAuditService courseAuditService;

    @Autowired
    private PrepareCourseService prepareCourseService;
  
    @Autowired
    private SsoCallService ssoCallService;
    
    @ApiOperation(value = "(新)获取审核课程列表信息",httpMethod = "POST")	
	@RequestMapping(value = "/course_list")
    public StatusResponse courseList(@RequestHeader(TICKET) String ticket, ClassesCoursePlanQuery query) {
        query.setCourseStatus(CourseConstant.CourseStatus.STARTING.codeOf());
        Page<WebCoursePlanListVo> coursePlanList = courseAuditService.getCourseList(query);
        return StatusResponse.success(coursePlanList);
    }

    @ApiOperation(value = "课程审核详情",httpMethod = "POST")
    @RequestMapping("/course_detail")
    public StatusResponse courseDetail(@RequestHeader(TICKET) String ticket, String coursePlanClassesId) {
        StaffDTO staff = ssoCallService.getStaffDTO(ticket);
        Map map = prepareCourseService.coursePADDetail(staff.getAreaId(), coursePlanClassesId);
        return StatusResponse.success(map);
    }
    
    @RequestMapping("/audit")
    public StatusResponse audit(@RequestHeader(TICKET) String ticket,String coursePlanClassesId, Integer opinion) {
        Boolean result = courseAuditService.audit(coursePlanClassesId, opinion);
        return StatusResponse.success(result);
    }

//    @RequestMapping("/get_kx_prepare_course_info_list")
//    public StatusResponse getPrepareCourseBaseInfoList(@RequestHeader(TICKET) String ticket,ClassesCoursePlanQuery query) {
//        query.setCourseStatus(CourseConstant.CourseStatus.STARTING.codeOf());
//       // Page<WebCoursePlanListVo> coursePlanList = courseAuditService.getKXCourseList(query);
//        List<WebCoursePlanListVo> WebCoursePlanList=courseAuditService.getKXPrepareCourseTeacherList(query);
//        List<TeacherDO> teacherList= new ArrayList();
//        List<CourseType> courseTypeList=new ArrayList();
//        List<String> ids = new ArrayList();
//        List<String> typenames = new ArrayList();
//
//        for(WebCoursePlanListVo webCoursePlanListVo:WebCoursePlanList){
//            if(!ids.contains(webCoursePlanListVo.getLastModifiedId())){
//            	StaffDTO staffDTO=ssoCallService.getStaffDTOById(webCoursePlanListVo.getLastModifiedId());
//            	TeacherDO teacher=new TeacherDO();
//            	teacher.setId(webCoursePlanListVo.getLastModifiedId());
//            	teacher.setName(webCoursePlanListVo.getLastModifiedName());
//            	teacher.setImgUrl(staffDTO.getHeadImgUrl());
//                teacherList.add(teacher);
//                ids.add(teacher.getId());
//            }
//           if(!typenames.contains(webCoursePlanListVo.getTypeName())){
//        	   CourseType courseType=new CourseType();
//        	   courseType.setType(webCoursePlanListVo.getCourseType());
//        	   courseType.setTypeCode(webCoursePlanListVo.getTypeCode());
//        	   courseType.setTypeName(webCoursePlanListVo.getTypeName());
//        	   courseTypeList.add(courseType);
//        	   typenames.add(webCoursePlanListVo.getTypeName());
//           }
//        }
//        Map map=new HashMap<>();
//        map.put("courseType", courseTypeList);
//        map.put("teacherList", teacherList);
//      // map.put("coursePlanList", coursePlanList);
//        return StatusResponse.success(map);
//     }

    
}
